package com.ohs.ohsoa.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ohs.ohsoa.system.dto.OvertimesettingDto;
import com.ohs.ohsoa.system.entity.Overtimesetting;
import com.ohs.ohsoa.system.mapper.OvertimesettingMapper;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OvertimesettingServiceImpl extends ServiceImpl<OvertimesettingMapper, Overtimesetting> implements OvertimesettingService {

    @Resource
    private OvertimesettingMapper overtimesettingMapper;

    @Override
    public List<Overtimesetting> overtimesettingSelectList(PageParam<OvertimesettingDto> pageParam) {
        OvertimesettingDto overtimesettingDto = pageParam.getSearchbean();
        // 分页
        PageHelper.startPage(pageParam.getIndexPage(), pageParam.getPageSize());
        List<Overtimesetting> overtimesettings = overtimesettingMapper.overtimesettingSelectList(overtimesettingDto);
        for(int i=0; i<overtimesettings.size(); i++){
            Overtimesetting a1 = overtimesettings.get(i);
            a1.setOsBtime(a1.getOsBtime().substring(11));
            a1.setOsEtime(a1.getOsEtime().substring(11));
            a1.setOsFeeTime(a1.getOsFeeTime().substring(11));
        }
        return  overtimesettings;
    }

    @Override
    public Overtimesetting overtimesettingSelectById(Overtimesetting overtimesetting) {
            String overtimesettingGuid = overtimesetting.getOsGuid();
            Overtimesetting overtimesettingById = overtimesettingMapper.overtimesettingSelectById(overtimesettingGuid);
            overtimesettingById.setOsBtime(overtimesettingById.getOsBtime().substring(11));
            overtimesettingById.setOsEtime(overtimesettingById.getOsEtime().substring(11));
            overtimesettingById.setOsFeeTime(overtimesettingById.getOsFeeTime().substring(11));
            return overtimesettingById;

    }

    @Override
    public Boolean overtimesettingUpdate(Overtimesetting overtimesetting) {
        String yearMonthDay = "1900-01-01 ";
        overtimesetting.setOsBtime(yearMonthDay + overtimesetting.getOsBtime());
        overtimesetting.setOsEtime(yearMonthDay + overtimesetting.getOsEtime());
        overtimesetting.setOsFeeTime(yearMonthDay + overtimesetting.getOsFeeTime());
        return overtimesettingMapper.overtimesettingUpdate(overtimesetting);
    }


}
